<template>
  <div class="body">
    <el-form ref="User" :model="User" class="loginContainer">
      <el-row class="loginTitle">
        <el-avatar :size="80" :src="circleUrl"></el-avatar>
      </el-row>
      <el-form-item prop="username">
        <el-input
          type="text"
          v-model="User.username"
          placeholder="亲，请输入用户名"
        >
        </el-input>
      </el-form-item>
      <el-form-item prop="user_password">
        <el-input
          type="password"
          v-model="User.user_password"
          placeholder="亲，请输入密码"
        >
        </el-input>
      </el-form-item>
      <!-- <el-form-item prop="code">
                <el-input type="text" auto-complete="false" v-model="User.code" placeholder="点击图片更换验证码" style="width: 250px;margin-right: 5px">
                </el-input>
                <img :src="captchaUrl">

            </el-form-item> -->
      <el-checkbox v-model="checked" class="loginRemember">记住我</el-checkbox>
      <el-button type="primary" style="width: 100%" @click="login"
        >登录</el-button
      >
    </el-form>
  </div>
</template>
 
 <script>
export default {
  data() {
    return {
      User: {
        username: "",
        user_password: "",
        code: "",
      },
      userToken: "",
      circleUrl: require("@/assets/tieba.jpg"),
      checked:false
    };
  },
  methods: {
    async login() {
      if (this.User.username === "" || this.User.user_password === "") {
        alert("账号或密码不能为空");
      } else {
       
        let res = await this.$http.post('validateClient',this.User);
        // console.log(res);
        //这里data存放的是后端返回的用户名，这里可以根据需要返回指定数据
        this.$store.commit("loginToken", res.data.token);
        this.$store.commit("login",res.data.user);
        localStorage.setItem('user_id', res.data.user_id);
        //跳转网站根目录，即首页
        this.$router.push("./");
      }
    },
  },
};
</script>
 <style scoped>
.loginContainer {
  border-radius: 15px;
  background-clip: padding-box;
  text-align: left;
  margin: auto;
  margin-top: 180px;
  width: 350px;
  padding: 15px 35px 40px 35px;
  background: aliceblue;
  border: 1px solid blueviolet;
  box-shadow: 0 0 25px #f885ff;
}
.touxiang {
  text-align: center;
}
.loginTitle {
  margin: 0px auto 48px auto;
  text-align: center;
  font-size: 40px;
}
.loginRemember {
  text-align: left;
  margin: 0px 0px 15px 0px;
}
.body {
  width: 100vw;
  height: 100vh;
  background-image: url("../assets/bgimg.jpeg");
  background-size: 100%;
  overflow: hidden;
}
</style>